# pybind11 include
INCS_ROOT = ./src/include
BINC = $(shell python -m pybind11 --include)
PINC = $(shell python3-config --includes)
INCS = $(BINC) $(PINC) -I$(INCS_ROOT)
SRCS_ROOT = ./src/source
SRCS = $(wildcard $(SRCS_ROOT)/*.cpp)
OBJS = $(patsubst %.cpp, %.o, $(SRCS))

CXXFLAGS = -std=c++11 $(INCS)

LFLAGS = -O3 -Wall

CC = @echo "c++ $@"; c++

TARGET = ./$(PROJ_NAME)$(shell python3-config --extension-suffix)

NAME = $(shell uname -a)
if [[ $(NAME) =~ "Darwin"]]; then
	LFLAGS += -Xlinker -undefined -Xlinker dynamic_lookup -flto=thin 

PPATH = $(shell python3-config --prefix)
TOROOT = $(shell find $(PPATH)/lib -maxdepth 2 -type d | grep site-packages)

all: $(TARGET)
$(TARGET):$(OBJS)
	$(CC) $(LFLAGS) $^ -o $@ 

%.o: %.cpp
	$(CC) -c -fPIC $(CXXFLAGS) $^ -o $@
	
show:
	@echo $(TOROOT)
install:
	mv $(TARGET) $(TOROOT)

clean:
	@echo "clean proj..."
	$(foreach ivar, $(OBJS), rm $(ivar))